package com.handydata.antifraud.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.web.AbsController;

import com.handydata.antifraud.common.exception.DecisionExecRecordExCode;
import com.handydata.antifraud.bo.decisionexecrecord.DecisionExecRecordReqBO;
import com.handydata.antifraud.bo.decisionexecrecord.DecisionExecRecordResBO;
import com.handydata.antifraud.vo.decisionexecrecord.CreateDecisionExecRecordReqVO;
import com.handydata.antifraud.vo.decisionexecrecord.CreateDecisionExecRecordResVO;
import com.handydata.antifraud.vo.decisionexecrecord.DeleteDecisionExecRecordReqVO;
import com.handydata.antifraud.vo.decisionexecrecord.DeleteDecisionExecRecordResVO;
import com.handydata.antifraud.vo.decisionexecrecord.ModifyDecisionExecRecordReqVO;
import com.handydata.antifraud.vo.decisionexecrecord.ModifyDecisionExecRecordResVO;
import com.handydata.antifraud.vo.decisionexecrecord.DecisionExecRecordBeanVO;
import com.handydata.antifraud.vo.decisionexecrecord.QueryDecisionExecRecordReqVO;
import com.handydata.antifraud.vo.decisionexecrecord.QueryDecisionExecRecordResVO;
import com.handydata.antifraud.service.DecisionExecRecordService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/decisionexecrecord")
@RestController
public class DecisionExecRecordController extends AbsController {
	
	private static final Logger logger = LoggerFactory.getLogger(DecisionExecRecordController.class);
	
	@Autowired
	private DecisionExecRecordService decisionExecRecordService;
	
	@ApiOperation(value="新增决策流执行记录表", notes="新增决策流执行记录表")
	@ApiImplicitParam(name = "req", value = "新增决策流执行记录表请求对象", required = true, dataType = "CreateDecisionExecRecordReqVO", paramType = "body")
	@PostMapping("/create")
	public CreateDecisionExecRecordResVO createDecisionExecRecord(@RequestBody CreateDecisionExecRecordReqVO req) {
		try {
			logger.info("Execute createDecisionExecRecord, param is {}", req);
			DecisionExecRecordReqBO reqBO = CommonBeanConvertor.convert(req, DecisionExecRecordReqBO.class);
			DecisionExecRecordResBO resBO = decisionExecRecordService.createDecisionExecRecord(reqBO);
			CreateDecisionExecRecordResVO res = CommonBeanConvertor.convert(resBO, CreateDecisionExecRecordResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, CreateDecisionExecRecordResVO.class, req, DecisionExecRecordExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="修改决策流执行记录表", notes="修改决策流执行记录表")
	@ApiImplicitParam(name = "req", value = "修改决策流执行记录表请求对象", required = true, dataType = "ModifyDecisionExecRecordReqVO", paramType = "body")
	@PostMapping("/modify")
	public ModifyDecisionExecRecordResVO modifyDecisionExecRecord(@RequestBody ModifyDecisionExecRecordReqVO req) {
		try {
			logger.info("Execute modifyDecisionExecRecord, param is {}", req);
			DecisionExecRecordReqBO reqBO = CommonBeanConvertor.convert(req, DecisionExecRecordReqBO.class);
			DecisionExecRecordResBO resBO = decisionExecRecordService.modifyDecisionExecRecord(reqBO);
			ModifyDecisionExecRecordResVO res = CommonBeanConvertor.convert(resBO, ModifyDecisionExecRecordResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, ModifyDecisionExecRecordResVO.class, req, DecisionExecRecordExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="删除决策流执行记录表", notes="删除决策流执行记录表")
	@ApiImplicitParam(name = "req", value = "修改决策流执行记录表请求对象", required = true, dataType = "DeleteDecisionExecRecordReqVO", paramType = "body")
	@PostMapping("/remove")
	public DeleteDecisionExecRecordResVO deleteDecisionExecRecord(@RequestBody DeleteDecisionExecRecordReqVO req) {
		try {
			logger.info("Execute deleteDecisionExecRecord, param is {}", req);
			DecisionExecRecordReqBO reqBO = CommonBeanConvertor.convert(req, DecisionExecRecordReqBO.class);
			DecisionExecRecordResBO resBO = decisionExecRecordService.deleteDecisionExecRecord(reqBO);
			DeleteDecisionExecRecordResVO res = CommonBeanConvertor.convert(resBO, DeleteDecisionExecRecordResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, DeleteDecisionExecRecordResVO.class, req, DecisionExecRecordExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="查询决策流执行记录表", notes="查询决策流执行记录表")
	@ApiImplicitParam(name = "req", value = "查询决策流执行记录表请求对象", required = true, dataType = "QueryDecisionExecRecordReqVO", paramType = "body")
	@PostMapping("/query")
	public QueryDecisionExecRecordResVO queryDecisionExecRecord(@RequestBody QueryDecisionExecRecordReqVO req) {
		try {
			logger.info("Execute queryDecisionExecRecord, param is {}", req);
			DecisionExecRecordReqBO reqBO = CommonBeanConvertor.convert(req, DecisionExecRecordReqBO.class);
			DecisionExecRecordResBO resBO = decisionExecRecordService.queryDecisionExecRecord(reqBO);
			QueryDecisionExecRecordResVO res = CommonBeanConvertor.convert(resBO, QueryDecisionExecRecordResVO.class, DecisionExecRecordBeanVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, QueryDecisionExecRecordResVO.class, req, DecisionExecRecordExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
}
